<?php

namespace collections\map;

use collections\set\Set;

abstract class AbstractMap implements Map
{

    public function size() {
        // return $this->entrySet()->size();
        return count($this->entrySet());
    }

    public function isEmpty() {
        return $this->size() == 0;
    }

    public function containsKey($key) {
        /** @var $entry Entry */
        foreach ($this->entrySet() as $entry) {
            if ($key == $entry->getKey()) {
                return true;
            }
        }
        return false;
    }

    public function containsValue($value)
    {
        /** @var $entry Entry */
        foreach ($this->entrySet() as $entry) {
            if ($value == $entry->getValue()) {
                return true;
            }
        }
        return false;
    }

    public function put($key, $value) {
        throw new \BadFunctionCallException("Unsupport operation: ".__METHOD__);
    }

    public function get($key) {
        /** @var $entry Entry */
        foreach ($this->entrySet() as $entry) {
            if ($key == $entry->getKey()) {
                return $entry->getValue();
            }
        }
        return null;
    }

    public function remove($key)
    {
    }

    public function putAll()
    {
        // TODO: Implement putAll() method.
    }

    public function keySet()
    {
        // TODO: Implement keySet() method.
    }

    public function values()
    {
        // TODO: Implement values() method.
    }

    /** @return array */
    public abstract function entrySet();
}